package com.hongxin.nw.netty.model.analysis.info;

import com.hongxin.nw.netty.utils.BinaryTools;
import com.hongxin.nw.netty.utils.FieldAnalysis;
import com.hongxin.nw.netty.values.TypeIdentif;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * @remark A.2鉴权数据
 * @author: GuoXiaolin
 * @date 2019/5/28 10:15
 * @Version 1.0
 * @Descibe
 */
@Slf4j
@Getter
@Setter
public class Mrena1_1 {

    private String co; //1	充电设备编号	压缩BCD码	8Byte	充电设备编号
    private String charge_inter_identify;//2	充电接口标识	BIN码	1Byte	充电设备为一桩多充时用来标记接口号，一桩一充时此项为0。多个接口时顺序对每个接口进行编号
    private String phcNum;//3	物理卡号	压缩BCD码	8Byte	16位编码
    private String cardPass;//4	卡密码	字符	16Byte	16位字符串，与输入密码相同（可选）
    private String enterPass;//5	输入密码	字符	16Byte	16位字符串
    private String cardMoney;//6	卡余额	BIN码	4Byte	全部置0
    private String cardStatus;//7	卡状态	BIN码	2Byte	全部置0
    private String vin;//8	电动汽车唯一标识	字符	32Byte	全部置0
    private String billing_model_id;//8	计费模型编码	压缩BCD码	8Byte	全部置0
    private String payCard;//10	支付卡卡号	压缩BCD码	8Byte	支付卡唯一标识号，充电设备中包含ESAM模块情况下，填写，其他情况置零。
    private String payCardData;//11	认证支付卡数据	压缩BCD码	8Byte 	充电设备中包含ESAM模块情况下，填写，其他情况置零。

    private int idx = 0;
    private ByteBuf byteBuf;

    private Mrena1_1 subCo() {
//        this.co = substring(TypeIdentif.BYTE_CO.getbyteLength());
//        this.co = FieldAnalysis.analysisBCD(this.co);
//        return this;

//        int byteLength = TypeIdentif.BYTE_CO.getInt();
//        this.co = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
//        this.co = FieldAnalysis.analysisBCD(this.co);
//        this.idx += byteLength;

        this.co = FieldAnalysis.subCo(TypeIdentif.BYTE_CO.getInt(),idx,byteBuf);
        this.idx += TypeIdentif.BYTE_CO.getInt();
        return this;
    }

    private Mrena1_1 subCharge_inte_identify() {
//        this.charge_inter_identify =  substring(TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getbyteLength());
//        this.charge_inter_identify = FieldAnalysis.analysisBin(this.charge_inter_identify);
//        return this;

//        int byteLength = TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getInt();
//        this.charge_inter_identify = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
//        this.charge_inter_identify = FieldAnalysis.analysisBin(this.charge_inter_identify);
//        this.idx += byteLength;

        this.charge_inter_identify = FieldAnalysis.subGun(TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getInt(),idx,byteBuf);
        this.idx += TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getInt();
        return this;
    }
    private Mrena1_1 subPhcisNum() {
//        this.phcisNum =  substring(TypeIdentif.BYTE_PHYSICS_NUM.getbyteLength());
//        this.phcisNum = FieldAnalysis.analysisBCD(this.phcisNum);
//        return this;

        int byteLength = TypeIdentif.BYTE_PHYSICS_NUM.getInt();
        this.phcNum = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
        this.phcNum = FieldAnalysis.analysisBCD(this.phcNum);
        this.idx += byteLength;
        return this;
    }
    private Mrena1_1 subCardPass() {
//        this.cardPass =  substring(TypeIdentif.BYTE_CARD_PASS.getbyteLength());
//        this.cardPass = FieldAnalysis.analysisBCD(this.cardPass);
//        return this;

        int byteLength = TypeIdentif.BYTE_CARD_PASS.getInt();
        this.cardPass = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
        this.cardPass = FieldAnalysis.analysisBCD(this.cardPass);
        this.idx += byteLength;
        return this;
    }
    private Mrena1_1 subEnterPass() {
//        this.enterPass =  substring(TypeIdentif.BYTE_ENTER_PASS.getbyteLength());
//        this.enterPass = FieldAnalysis.analysisBCD(this.enterPass);
//        return this;

        int byteLength = TypeIdentif.BYTE_ENTER_PASS.getInt();
        this.enterPass = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
        this.enterPass = FieldAnalysis.analysisBCD(this.enterPass);
        this.idx += byteLength;
        return this;
    }
    private Mrena1_1 subCardMoney() {
//        this.cardMoney =  substring(TypeIdentif.BYTE_CARD_MONEY.getbyteLength());
//        this.cardMoney = FieldAnalysis.analysisBin(this.cardMoney);
//        return this;

        int byteLength = TypeIdentif.BYTE_CARD_MONEY.getInt();
        this.cardMoney = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
        this.cardMoney = FieldAnalysis.analysisBin(this.cardMoney);
        this.idx += byteLength;
        return this;
    }
    private Mrena1_1 subCardStatus() {
//        this.cardStatus =  substring(TypeIdentif.BYTE_CARD_STATUS.getbyteLength());
//        this.cardStatus = FieldAnalysis.analysisBin(this.cardStatus);
//        return this;

        int byteLength = TypeIdentif.BYTE_CARD_STATUS.getInt();
        this.cardStatus = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
        this.cardStatus = FieldAnalysis.analysisBin(this.cardStatus);
        this.idx += byteLength;
        return this;
    }
    private Mrena1_1 subA() {
//        this.a =  substring(TypeIdentif.BYTE_CAR_IDENTIFY_32.getbyteLength());
//        this.a = FieldAnalysis.caseVin(this.a);
//        return this;

        int byteLength = TypeIdentif.BYTE_CAR_IDENTIFY_32.getInt();
        this.vin = BinaryTools.subByteBufToVIN(byteLength, idx, byteBuf);
//        this.a = FieldAnalysis.caseVin(this.a);
        this.idx += byteLength;
        return this;
    }

    private Mrena1_1 subBilling_model_id() {
//        this.billing_model_id =  substring(TypeIdentif.BYTE_BILLING_MODEL_ID.getbyteLength());
//        this.billing_model_id = FieldAnalysis.analysisBCD(this.billing_model_id);
//        return this;

//        int byteLength = TypeIdentif.BYTE_BILLING_MODEL_ID.getInt();
//        this.billing_model_id = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
//        this.billing_model_id = FieldAnalysis.analysisBCD(this.billing_model_id);
//        this.idx += byteLength;

        this.billing_model_id = FieldAnalysis.subBill(TypeIdentif.BYTE_BILLING_MODEL_ID.getInt(),idx,byteBuf);
        this.idx += TypeIdentif.BYTE_BILLING_MODEL_ID.getInt();
        return this;
    }

    private Mrena1_1 subPayCard() {
//        this.payCard =  substring(TypeIdentif.BYTE_PAY_NUM.getbyteLength());
//        this.payCard = FieldAnalysis.analysisBCD(this.payCard);
//        return this;

        int byteLength = TypeIdentif.BYTE_PAY_NUM.getInt();
        this.payCard = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
        this.payCard = FieldAnalysis.analysisBCD(this.payCard);
        this.idx += byteLength;
        return this;
    }


    private Mrena1_1 subPayCardData() {
//        this.payCardData =  substring(TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getbyteLength());
//        this.payCardData = FieldAnalysis.analysisBCD(this.payCardData);
//        return this;

        int byteLength = TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getInt();
        this.payCardData = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
        this.payCardData = FieldAnalysis.analysisBCD(this.payCardData);
        this.idx += byteLength;


        return this;
    }


    public Mrena1_1 analysisStr(int idx, ByteBuf byteBuf) {
        this.idx = idx;
        this.byteBuf = byteBuf;

        return this.subCo()
                .subCharge_inte_identify()
                .subPhcisNum()
                .subCardPass()
                .subEnterPass()
                .subCardMoney()
                .subCardStatus()
                .subA()
                .subBilling_model_id()
                .subPayCard()
                .subPayCardData();
    }
    @Override
    public String toString() {
        return "Mrena1_1{" +
                "co='" + co + '\'' +
                ", charge_inter_identify='" + charge_inter_identify + '\'' +
                ", phcNum='" + phcNum + '\'' +
                ", cardPass='" + cardPass + '\'' +
                ", enterPass='" + enterPass + '\'' +
                ", cardMoney='" + cardMoney + '\'' +
                ", cardStatus='" + cardStatus + '\'' +
                ", vin='" + vin + '\'' +
                ", billing_model_id='" + billing_model_id + '\'' +
                ", payCard='" + payCard + '\'' +
                ", payCardData='" + payCardData + '\'' +
                '}';
    }
}
